<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>登录页面</title>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <meta name="renderer" content=webkit>
    <script src="/static/vonder/jquery-3.4.1/jquery-3.4.1.js"></script>
</head>
<body onkeydown="keyLogin();">
<div class="loginbox">
    <div class="title">
    </div>
    <div class="formbox">
        <input type="text" placeholder="请输入用户名" id="username" autocomplete="off" value="ava">
    </div>
    <div class="formbox">
        <input type="password" id="password" placeholder="请输入用户密码" class="password" autocomplete="off" value="asd">
    </div>
    <div class="rememberbox">
        <div class="remember">
            <label for="">
                <input type="checkbox" name="rememberMe"/>记住密码
            </label>
        </div>
    </div>
    <div class="btnbox">
        <button class="login" type="button" onclick="loginUser()">登录</button>
    </div>
</div>
</body>
<script>
    $(document).ready(function () {
    });

    $('.password').bind('keyup', function (event) {
        if (event.keyCode == "13") {
            //回车执行查询
            loginUser();
        }
    });

    function keyLogin() {
        if (event.keyCode == 13)  //回车键的键值为13
            loginUser() //调用登录按钮的登录事件
    }

    function loginUser() {
        let username = $("#username").val();
        let password = $("#password").val();

        if (username == "") {
            layer.msg("用户名称不能为空");
            return false;
        }
        if (password == "") {
            layer.msg("用户密码不能为空");
            return false;
        }
        var rememberMe = $("input[name='rememberMe']").is(':checked');
        var param = {
            username: username, password: password, rememberMe,type:1
        }
        $.ajax({
            url: '/user/login',
            type: 'post',
            contentType: 'application/json',
            //contentType:"application/x-www-form-urlencoded; charset=UTF-8",
            data: JSON.stringify(param),
            //dataType: 'text',
            success: function (data) {
                if(data.success==true){
                    window.location.href = "index";
                }else{
                    alert(data.msg)
                }

            },
            fail:function (data){
                alert(data)
            }
        })
    }

</script>
</html>

